window.onload=function(){
	$POSMENU=2;
	new CHECKLOGIN().check();
	new CLIP().list();
	document.myform.reset();
}
CLIP=function(){}
CLIP.prototype.list=function(){
	var fncSuc = XHR.Delegate(this,this.listSuc);
	var param = {action:"getClip"};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
}
CLIP.prototype.listSuc=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		var il = xml.getElementsByTagName("item");
		var html = "",path="",img="";
		for(var i=0; i < il.length; i++){
			path = genLinkClip(il[i].getAttribute("id"),il[i].getAttribute("path"));
			img = genLinkImg(il[i].getAttribute("id"),il[i].getAttribute("thumbnail"));
			html+="<table cellpadding=\"0\" style=\"margin-bottom:5px;border-bottom: 1px solid #cccccc;width:100%;cursor:pointer\" cellspacing=\"0\"><tr>" +
						"<td valign=\"top\" width=\"55px\" style=\"padding-bottom:5px\">" +
							"<div style=\"width:50px;height:40px;overflow:hidden;cursor:pointer\" onClick=\"clickDetail('"+il[i].getAttribute("id")+"')\"><img src=\""+genLinkImg(il[i].getAttribute("id"),il[i].getAttribute("thumbnail").replace(".","thumb."))+"\" width=\"50px\"></div>"+
						"</td>" +
						"<td valign=\"top\"><div  onClick=\"clickDetail('"+il[i].getAttribute("id")+"')\" style=\"cursor:pointer\"><b>"+il[i].getAttribute("name")+"</b></div>"+
						"<div style=\"font-size:11px;padding-top:5px;cursor:pointer\"><span onClick=\"deleteClip('"+il[i].getAttribute("id")+"')\">[Xóa]</span>&nbsp;&nbsp;" +
						"<span style=\"cursor:pointer\" onClick=\"playClip('"+path+"','"+img+"')\">[Play]</span></div>"+
						"</td>"+
					"</tr>" +
					"</table>";
					
		}
		$("listClip").innerHTML = html;
	}
}
CLIP.prototype.detail=function(clipId){
	var fncSuc = XHR.Delegate(this,this.detailSuc);
	var param = {action:"clipDetail",clipId:clipId};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
}
CLIP.prototype.detailSuc=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		var il = xml.getElementsByTagName("item")[0];
		$N("clipName")[0].value = il.getAttribute("name");
		$N("clipDate")[0].value = fulldateSQLtoN(il.getAttribute("date"));
		$N("clipDesc_")[0].value = il.getAttribute("description").replace(/<br>/g,"\n");
		$N("clipThumbnail")[0].value = il.getAttribute("thumbnail");		
		$N("clipPath")[0].value = il.getAttribute("path");		
		$N("clipId")[0].value = il.getAttribute("id");
		$N("cat")[il.getAttribute("cat")].checked=true;
		$N("catid")[0].value = il.getAttribute("cat");
	}
}
CLIP.prototype.deleteClip=function(clipId){
	var fncSuc = XHR.Delegate(this,this.deleteClipSuc);
	var param = {action:"deleteClip",clipId:clipId};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
	this.clipId = clipId;
}
CLIP.prototype.deleteClipSuc=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		this.list();
		if(this.clipId==$N("clipId")[0].value)
			document.myform.reset();
	}
}

function preSubmit(action){
	$N("action")[0].value = action;
	$N("catid")[0].value = "4";
	if($N("clipName")[0].value==""||$N("catid")[0].value==""||$N("clipDate")[0].value==""){
		alert("Vui lòng kiểm tra tên clip, chuyên mục, ngày");
		return;
	}
	$N("clipDesc")[0].value = $N("clipDesc_")[0].value.replace(/\n/g,"<br>").replace(/\r/g,"");
	
	
	document.myform.submit();
}
function onUpload(value, msg){
	if(value=="true"){
		new CLIP().list();
		document.myform.reset();
		alert("Done");
	}else{
		alert("Đã có lỗi xảy ra. Vui lòng kiểm tra lại thông tin (ngày tháng, tiêu đề,...)");
	}
}
function clickDetail(clipId){
	new CLIP().detail(clipId)
}
function deleteClip(clipId){
	if(confirm("Bạn có chắc muốn xóa?"))
		new CLIP().deleteClip(clipId);
}
function playClip(path,img){
	var temp = genPathClip(path,560,330,img,true);
	var temp2 = genPathClip(path,560,330,img,false);
	$N("embedInput")[0].value = temp2;
	$("embed").innerHTML = temp;
	$("embed").style.textAlign="center";
}
function genPathClip(path,width,height,img,autostart){
	var imgplayer="";
	if(img!=""){
		imgplayer = "&image="+img;
	}
	var temp = "<embed wmode='transparent' flashvars='file="+path+imgplayer+"&autostart="+autostart+"&repeat=list&bufferlength=5' " +
	"allowfullscreen='true' " +
	"allowscripaccess='always' " +
	"autostart='true' " +
	"id='player1' " +
	"name='player1' " +
	"src='jwplayer.swf' " +
	"width='"+width+"' " +
	"height='"+height+"' " +
	"/>";
	return temp;
}
function viewLink(){
	var param = $N("linkview")[0].value;
	var newsid = param.split("/")[5];
	clickDetail(newsid);
	clickDetail(newsid);
}
function clickCat(catid){
	$N("catid")[0].value = "4";
}
var setRemoveCallback = function() {
        __flash__removeCallback = function(instance, name) {
            if(instance) {
                instance[name] = null;
            }
        };
        window.setTimeout(setRemoveCallback, 10);
    };
    setRemoveCallback();
(function(){var s=function(){__flash__removeCallback=function(i,n){if(i)i[n]=null;};window.setTimeout(s,10);};s();})();